<html>
<head><meta charset="utf-8"><title>Pretty printing chunks of AST · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Pretty.20printing.20chunks.20of.20AST.html">Pretty printing chunks of AST</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="223143181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Pretty%20printing%20chunks%20of%20AST/near/223143181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sean Klein <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Pretty.20printing.20chunks.20of.20AST.html#223143181">(Jan 18 2021 at 16:50)</a>:</h4>
<p>Hey all, I have a noobish question which is hopefully easy-to-answer for people that regularly hack on the compiler.</p>
<p>I'm poking at rustfmt (checked out and recompiled), and I'm trying to print more information about the AST to get my bearings. I'm noticing that basically all parts of the AST have a span, but I really want a way to pretty print "here is the chunk of the original source - as a string - that corresponds with this span", rather than the "low and high byte positions".</p>
<p>Is there a good way to do this conversion?</p>
<p>Context: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.SpanData.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.SpanData.html</a></p>



<a name="223143254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Pretty%20printing%20chunks%20of%20AST/near/223143254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Pretty.20printing.20chunks.20of.20AST.html#223143254">(Jan 18 2021 at 16:51)</a>:</h4>
<p><span class="user-mention" data-user-id="284803">@Sean Klein</span> do one of the <code>-Z unpretty</code> options help?</p>



<a name="223143621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Pretty%20printing%20chunks%20of%20AST/near/223143621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oliver <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Pretty.20printing.20chunks.20of.20AST.html#223143621">(Jan 18 2021 at 16:54)</a>:</h4>
<p>maybe: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/source_map/struct.SourceMap.html#method.span_to_snippet">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/source_map/struct.SourceMap.html#method.span_to_snippet</a></p>



<a name="223143851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Pretty%20printing%20chunks%20of%20AST/near/223143851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Sean Klein <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Pretty.20printing.20chunks.20of.20AST.html#223143851">(Jan 18 2021 at 16:57)</a>:</h4>
<p>oooo the <code>-Z unpretty</code> looks useful for getting familiar with a specific file output, but that <code>span_to_snippet</code> method looks like what I'm looking for - thanks!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>